package com.baoyouqun.controller.weixin;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.cola.dto.SingleResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baoyouqun.base.PageResponse;
import com.baoyouqun.domain.CreateCmd.InvoiceRecordCreateCmd;
import com.baoyouqun.domain.Query.InvoiceRecordPageQuery;
import com.baoyouqun.domain.VO.InvoiceRecordVO;
import com.baoyouqun.domain.VO.OrderRecordVO;
import com.baoyouqun.service.InvoiceRecordService;
import com.baoyouqun.service.OrderRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wx/invoiceRecord")
@Api(tags = "发票记录表管理接口")
public class WxInvoiceRecordController {

    @Resource
    private InvoiceRecordService invoiceRecordService;
    @Resource
    private OrderRecordService orderRecordService;

    @GetMapping("selectOrderByUserId")
    @ApiOperation("查询用户订单记录表")
    public SingleResponse<List<OrderRecordVO>> selectByUserId() {
        return SingleResponse.of(orderRecordService.selectByUserId(StpUtil.getLoginIdAsString()));
    }


    @PostMapping("create")
    @ApiOperation("新增发票记录表")
    public SingleResponse<InvoiceRecordVO> create(@Valid @RequestBody InvoiceRecordCreateCmd cmd) {
        cmd.setUserId(StpUtil.getLoginIdAsString());
        return invoiceRecordService.create(cmd);
    }

    @GetMapping("getById")
    @ApiOperation("根据ID查询发票记录表")
    public SingleResponse<InvoiceRecordVO> selectById(String id) {
        return SingleResponse.of(invoiceRecordService.selectById(id));
    }

    @GetMapping("page")
    @ApiOperation("分页查询发票记录表")
    public PageResponse<InvoiceRecordVO> page(InvoiceRecordPageQuery query) {
        query.setUserId(StpUtil.getLoginIdAsString());
        IPage<InvoiceRecordVO> page = invoiceRecordService.pageVo(query);
        return PageResponse.of(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
    }
}